import React, {Component} from 'react';
import './index.less';
import {base} from 'nc-lightapp-front';
import SearchTop from "../SearchTop";
import {getQueryCondition} from "src/hrpub/common/utils/utils";

class SearchModal extends Component {
    constructor(props) {
        super(props);
        this.goSearch = this.goSearch.bind(this);
    }

    goSearch() {
        const {updateState, getAgreeTableData, queryOid, search, pageInfo} = this.props;
        const data = getQueryCondition(this.props, 'agreementquery');
        const topData = this.searchTopNode.getData();
        updateState({
            agreementPageInfo: {
                ...pageInfo,
                pageIndex: 1
            },
            agreeSearchModalValue: {...data, ...topData, oid: queryOid}
        }, () => {
            getAgreeTableData(true);
            search.openAdvSearch('agreementquery', false)
        });
    }

    render() {
        return (
            <div style={{display: 'none'}}>
                {this.props.search.NCCreateSearch('agreementquery', {
                    clickSearchBtn: this.goSearch,
                    onlyShowAdvArea: false,
                    showAdvSearchPlanBtn: true,
                    saveSearchPlan: true,
                    oid: this.props.queryOid,
                    onlyShowSuperBtn: true,
                    advSearchClearEve: () => {
                        this.searchTopNode.clearData()
                    },
                    addAdvBody: () => {
                        return <SearchTop
                            ref={node => this.searchTopNode = node}
                            isAgree={true}
                            json={this.props.json}
                        />
                    }
                })}
            </div>
        );
    }
}

export default SearchModal;